﻿
@{
    ViewBag.Title = "登录";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<el-col :span="6" :offset="9">
    <el-card class="box-card loginbox">
        <div style="margin:25px 0">登录MPic</div>
        <el-form status-icon label-width="0px" ref="loginForm" class="demo-ruleForm">
            <el-form-item prop="email">
                <el-input v-model="loginData.email" placeholder="请输入登录邮箱">
                    <template slot="prepend">
                        邮箱
                    </template>
                </el-input>
            </el-form-item>
            <el-form-item prop="password">
                <el-input v-model="loginData.password" placeholder="请输入登录密码" type="password" auto-complete="off">
                    <template slot="prepend">
                        密码
                    </template>
                </el-input>
            </el-form-item>
            <el-button type="primary" :loading="loging" style="width:100%" @@click="login()">立即登录</el-button>
            <div style="text-align:right">
                <el-button type="text" style="margin-top:10px;">忘记密码</el-button>
                <el-button type="text" style="margin-top:10px;" @@click="handleSelect('6')">免费注册</el-button>
            </div>
        </el-form>
    </el-card>
</el-col>
@section scripts{
    <script type="text/javascript">
        new Vue({
            el: "#app",
            data: {
                limit: 10,
                ismultiple: false,
                isshowfilelist: true,
                activeIndex: '5',
                loging: false,
                loginData: {
                    email: '',
                    password: ''
                },
                rules: {
                    name: [
                        { required: true, message: '请输入登录邮箱', trigger: 'blur' },
                    ],
                    password: [
                        { required: true, message: '请输入登录密码', trigger: 'blur' }
                    ]
                }
            },
            methods: {
                handleSelect(key, keyPath) {
                    var self = this;
                    skipPage(self, key);
                },
                login() {
                    var self = this;
                    self.loging = true;
                    if (self.loginData.email == '') {
                        self.loging = false;
                        showMessage(self, '提示：登录邮箱为空.', true, 'warning');
                        return;
                    }
                    if (self.loginData.password == '') {
                        self.loging = false;
                        showMessage(self, '提示：登录密码为空.', true, 'warning');
                        return;
                    }
                    Axios.post(self, '/main/login', {
                        data: {
                            email: self.loginData.email,
                            password: self.loginData.password
                        },
                        success(res) {
                            //showMessage(self, res.msg, true);
                            window.location.href = "/main/index";
                        },
                        error(res) {
                            showMessage(self, res.msg);
                        }
                    });
                    self.loging = false;
                }
            },
            created() {
                var self = this;
                //键盘回车键按下事件
                window.onkeydown = function (e) {
                    var keycode = e.keyCode;
                    if (e == null) { //ie
                        keycode = event.keyCode;
                    } else { // mozilla
                        keycode = e.which;
                    }
                    if (keycode == 13) {
                        self.login();
                    }
                }
            }
        });
    </script>
}
